package com.mq.direct;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author ytj
 * @date 2024/1/11
 */
@Component
public class Demo1Producer {
    @Resource
    private RabbitTemplate rabbitTemplate;

    /**
     * 发送消息
     * exchange+route
     * */
    public void send(){
        Demo1Message message=new Demo1Message("发送消息",System.currentTimeMillis()+"");
        rabbitTemplate.convertAndSend(Demo1Message.ExCHANGE_NAME,Demo1Message.ROUTE_KEY,message);
    }

    /**
     * 发送默认消息
     * queue
     * rabbitmq具有默认交换机
     * */
    public void sendDefault(){
        Demo1Message message=new Demo1Message("发送默认消息",System.currentTimeMillis()+"");
        rabbitTemplate.convertAndSend(Demo1Message.QUEUE_NAME,message);
    }




}
